﻿@model ChoiceModel

@{
    var controlId = Model.BuildControlId();
    var items = Model.Values ?? new List<ChoiceItemModel>();

    // TODO: (mc) Replace .radio with .form-radio
}

@foreach (var item in items)
{
    var checkId = controlId + "_" + item.Id;
    var hasColor = item.Color.HasValue() && item.Color != "transparent";
    <div class="radio" title="@item.Title.NullEmpty()">
        <label class="form-radio-label choice-item@(item.IsUnavailable ? " choice-item-unavailable" : "")">
            <input class="form-radio-input" type="radio" id="@checkId" name="@controlId" value="@item.Id" 
                   attr-checked='(item.IsPreSelected, "checked")' attr-disabled='(item.IsDisabled, "disabled")' />

            @if (item.ImageUrl.HasValue())
            {
                if (item.SeName.HasValue())
                {
                    <a asp-route="Product" asp-route-SeName="@item.SeName" class="choice-item-img">
                        <img src="@item.ImageUrl" />
                    </a>
                }
                else
                {
                    <img src="@item.ImageUrl" class="choice-item-img" />
                }
            }
            else if (hasColor)
            {
                <span class="choice-item-color" style="background-color: @item.Color"></span>
            }

            @item.GetItemLabel()
        </label>
    </div>
}